<?php


namespace BoojasrFramework\DependencyInjection\Compiler;


use BoojasrFramework\Kernel;
use BoojasrFramework\ServicesContainer\ContainerBuilder;
use BoojasrFramework\Service\DoctrineManageService;
use BoojasrFramework\ServicesContainer\DependencyInjection\Compiler\CompilerPassInterface;

class DoctrinePass implements CompilerPassInterface
{

    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition("doctrine")){
            return ;
        }
        /** @var DoctrineManageService $doctrine */
        $doctrine = $container->get("doctrine");
        $config = Kernel::getDatabaseConfig();
        if (isset($config["connections"])){
            $doctrine->setConnections($config["connections"]);
        }
        if (isset($config["default_connection"])){
            $doctrine->setDefaultConnection($config["default_connection"]);
        }
        if (isset($config["entity_paths"])){
            $doctrine->setEntityPaths($config["entity_paths"]);
        }
    }
}